package exam.bank.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import exam.bank.service.BankService;
import exam.bank.service.impl.BankServiceImpl;
import exam.utils.JDBCUtil;

/**
 * Servlet implementation class BankController
 */
public class BankController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		BankService service=new BankServiceImpl();
		Map<String,Object>mp=new HashMap<String,Object>();
		String method=request.getParameter("method");
		
		if("addBank".equals(method)){
			
			String bankName=request.getParameter("bankName");
			String bankPhone=request.getParameter("bankPhone");
			String bankAddress=request.getParameter("bankAddress");
			
			service.addBank(bankName, bankPhone, bankAddress, mp);
		}else if("findAllBank".equals(method)){
			String cur=request.getParameter("cur");
    		String ps=request.getParameter("ps");
			service.findAllBank(cur,ps,mp);
		}else if("updateBank".equals(method)){
			String upStr=request.getParameter("upStr");
			service.findBankById(upStr, mp);
		}else if("updateBank1".equals(method)){
			String bankId=request.getParameter("bankId");
			String bankName=request.getParameter("bankName");
			String bankPhone=request.getParameter("bankPhone");
			String bankAddress=request.getParameter("bankAddress");
			
			service.updateBank(bankId, bankName, bankPhone, bankAddress, mp);
		}else if("deleteBank".equals(method)){
			String delStr=request.getParameter("delStr");
			
			service.deleteBank(delStr, mp);
		}
		
		JDBCUtil.printJson(response, mp);
	}
}
